//
//  CZForwardViewController.swift
//  GZWeibo666
//
//  Created by donghai on 15/12/1.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class CZdetailViewController: UITableViewController {

    //MARK:-属性
//    /// 要显示的微博数据
//    var statuses: CZStatus? {
//        didSet {
//            // 刷新tableView的数据
//            tableView.reloadData()
//        }
//    }
    /// 微博模型
    private var status: CZStatus
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 构造函数
    init(status: CZStatus) {
        self.status = status
        super.init(nibName: nil, bundle: nil)
    }

    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "微博详情"
        
        // 注册cell,需要注册2个,根据显示的模型返回对应类型的cell
        tableView.registerClass(CZStatusNormalCell.self, forCellReuseIdentifier: CZStatusReuseIdentifier.NormalCell.rawValue)
        tableView.registerClass(CZStatusForwardCell.self, forCellReuseIdentifier: CZStatusReuseIdentifier.ForwardCell.rawValue)
    
    }
    ///MARK:-UITableViewController 数据源方法
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        if indexPath.section == 0 {
            
            let cell = tableView.dequeueReusableCellWithIdentifier(status.cellId()) as! CZStatusCell
            
            let rowHeight = cell.rowHeight(status)
            
            return rowHeight
        }
        
        return 44
    }
    
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        
        let cell = tableView.dequeueReusableCellWithIdentifier(status.cellId()) as! CZStatusCell
        
        if (status.retweeted_status != nil) {
            
            let forwardCell =  cell as! CZStatusForwardCell
            forwardCell.coverButton.addTarget(self, action: "coverButtonClick", forControlEvents: UIControlEvents.TouchUpInside)
        }
        
        cell.status = status

        return cell
    }
    
    //遮盖按钮的点击事件
    func coverButtonClick(){
        let FwDVc = CZForwardDetailViewController()
        FwDVc.hidesBottomBarWhenPushed = true
        navigationController?.pushViewController(FwDVc, animated: true)
        
    }
}


